<?php
namespace IFeng\Process;
require_once 'IFeng/Process/MainProcess.php';
class Process {
	/**
	 * @var MainProcess
	 */
	protected static $_current;
	/**
	 * @var int
	 */
	private $_pid;
	/**
	 * @param int $pid
	 */
	protected function __construct($pid) {
		$this->_pid = $pid;
	}
	/**
	 * @return Process
	 */
	public static function process($pid) {
		return new self($pid);
	}
	/**
	 * @return MainProcess
	 */
	public static function current() {
		$pid = posix_getpid();
		if (!self::$_current || $pid != self::$_current->getPid()) {
			self::$_current = new MainProcess($pid);
		}
		return self::$_current;
	}
	
	/**
	 * @return int
	 */
	public function getPid() {
		return $this->_pid;
	}
	
	/**
	 * @return boolean
	 */
	public function isCurrent() {
		return posix_getpid() == $this->_pid;
	}
}